#!/bin/bash

#
# slimbin -- by Dario Berzano <dario.berzano@gmail.com>
#
# Part of the lfscripts suite -- http://lfscripts.googecode.com/
#
# Slims a Universal Binary by keeping only the specified architecture. It works
# only on Macs and it uses ditto. Use with care!
#

#
# Functions
#

# Main function
function Main() {

  if [ "$1" == "" ]; then
    echo "Usage: $0 <arch_to_keep> [app1.app [app2.app...]]"
    echo "Where arch can be, for instance: ppc7400, i386, x86_64..."
    exit 1
  fi

  local ARCH=$1
  shift
  local TMPAPP="temporary_slimbin_app.app"

  for APP in "$@"
  do
    echo "---> Processing $APP..."
    ditto --rsrc --arch "$ARCH" "$APP" "$TMPAPP" &&
      rm -rf "$APP" &&
      mv "$TMPAPP" "$APP"
  done

}

#
# Entry point
#

Main "$@"
